import Button from 'antd';
import { Component } from 'react';
import { history } from 'umi';
import Action from './action';
import styles from './index.less';

export default class Footer extends Component {
  static Action = Action;
  static defaultProps = {
    actions: [],
    onBack: history.goBack,
  };

  handleBack = () => {
    const { onBack } = this.props;
    onBack();
  };

  render() {
    const { actions, children, leftExtra } = this.props;
    return (
      <div className={styles.wrap}>
        <div className={styles.footer}>
          {leftExtra}
          <Action onClick={this.handleBack}>返回</Action>
          {actions.map((action, aIndex) => {
            const { title, className, ...restAction } = action;
            return (
              <Button key={aIndex} className={className} {...restAction}>
                {title}
              </Button>
            );
          })}
          {children}
        </div>
      </div>
    );
  }
}
